<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>app用户管理</title>
  <%@ include file="/WEB-INF/view/common/includ-css.jsp" %>
<%--  <link rel="stylesheet" href="../../static/lib/layui/css/layui.css" media="all" />--%>
  <style>
    .layui-table1 {
      margin: 10px 0;
      width: 100%;
      margin: 10px 0;
      border-collapse: collapse;
    }
    .layui-table1 th {
      font-weight: 400;
      position: relative;
      padding: 9px 15px;
      min-height: 20px;
      line-height: 20px;
      font-size: 14px;
    }
  </style>
</head>
<body class="gray-bg">
<div class="row wrapper border-bottom white-bg">
  <div class="col-sm-12">
    <div class="ibox float-e-margins" style="margin-bottom: 0px;">
      <div class="ibox-title">
        <h5>查询条件</h5>
        <div class="ibox-tools">
          <a class="collapse-link">
            <i class="fa fa-chevron-up"></i>
          </a>
        </div>
      </div>
      <div class="ibox-content">
        <form class="form-inline">
          <div class="form-group">
            <label class="font-normal">手机号码：</label>
            <input type="text" id="mobile" name="mobile"/>
          </div>
          <div class="form-group">
            <label class="font-normal">用户昵称：</label>
            <input type="text" id="nickName" name="nickName"/>
          </div>
          <div class="form-group">
            <label class="font-normal">用户id：</label>
            <input type="text" id="uid" name="uid"/>
          </div>
          <div class="form-group">
            <label class="font-normal">alias：</label>
            <input type="text" id="alias" name="alias"/>
          </div>
          <div class="form-group">
            <label class="font-normal">用户状态：</label>
            <select class="form-control" id="status">
              <option value="-1">全部</option>
              <option value="0">正常</option>
              <option value="1">注销</option>
              <option value="2">禁用</option>
            </select>
          </div>
          <div class="form-group">
            <label class="font-normal">alipayUid：</label>
            <input type="text" id="alipayUid" name="alipayUid"/>
          </div>
          <div class="form-group">
            <label class="font-normal">alipayName：</label>
            <input type="text" id="alipayName" name="alipayName"/>
          </div>
          <input type="hidden" id="statusInput"/>
          <button type="button" class="btn btn-white btn-info btn-round" style="margin-bottom: 0px;" id="query">
            <i class="ace-icon fa fa-search bigger-120 blue"></i>查询
          </button>
        </form>
      </div>
    </div>
  </div>
</div>
<div class="row wrapper border-bottom white-bg page-heading">
  <div class="col-sm-4">
    <h2>用户管理</h2>
  </div>
</div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
  <div class="row">
    <div class="col-sm-12">
      <div class="ibox float-e-margins">

        <div class="ibox-content">
          <table id="dataTables" class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
              <th>ID</th>
              <th>银行卡余额</th>
              <th>支付宝余额</th>
              <th>昵称</th>
              <th>头像</th>
              <th>电话</th>
              <th>实名信息</th>
              <th>商户号</th>
              <th>拉黑</th>
              <th>状态/群主</th>
              <th>创建时间</th>
              <th>提现状态</th>
              <th>支付宝id</th>
              <th>支付宝昵称</th>
              <th>ip</th>
              <th>推荐人</th>
              <th>操作</th>
            </tr>
            </thead>
            <tbody></tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>

<%@ include file="/WEB-INF/view/common/includ-js.jsp" %>
<!-- Data Tables -->
<script src="${path}/static/Hui/js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="${path}/static/Hui/js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="${path}/static/plugins/layui/layui.all.js"></script>
<script>
  var tables;
  $(function(){

    // 关闭错误提示
    $.fn.dataTable.ext.errMode = 'none';
    // 数据表格
    $("#query").click(function(){
      if(tables){
        tables.dataTable().fnDraw();
      }
      tables = $("#dataTables").dataTable({
        paging:true,
        serverSide: true,
        searching: false,
        ordering:  false,
        processing: false,
        "lengthMenu": [10, 20, 50, 100],
        pageLength: 20,
        lengthChange: true,
        destroy: true,
        searching: false,
        "ajax":{
          url:"/app/user/list",
          type:"post",
          data: function (d) {
            d.mobile=$("#mobile").val(),
                    d.status=$("#status").val(),
                    d.nickName=$("#nickName").val(),
                    d.id=$("#uid").val(),
                    d.alias = $("#alias").val(),
                    d.alipayUid=$("#alipayUid").val(),
                    d.alipayName = $("#alipayName").val();
          }
        },
        columns: [
          { "data": "id" },
          { "data": "amount" },
          { "data": "zfbAmount" },
          { "data": "nickName" },
          { "data": "avatarUrl" },
          { "data": "phone" },
          { "data": "realName" },
          { "data": "merchantNo" },
          { "data": "isBlack" },
          { "data": "groupApplyStatus" },
          { "data": "create_time" },
          { "data": "userWithdrawBlack" },
          { "data": "alipayUid" },
          { "data": "alipayName" },
          { "data": "ip" },
          { "data": "inviteUid" },
          { "data": "id" },
        ],
        columnDefs: [
          {
            "render": function(data, type, row, meta) {
              return '<a href="/app/user/user/bank/index?id='+row.id+'" class="blue" title="银行卡信息"><i style="font: normal normal normal 14px/1 FontAwesome;">'+data+'</i></a>';
            },
            "targets": 1
          },
          {
            "render": function(data, type, row, meta) {
              return '<a href="javascript:void(0)" onclick="userConfig(' + row.id + ')" class="blue" title="配置信息"><i style="font: normal normal normal 14px/1 FontAwesome;">'+data+'</i></a>';
            },
            "targets": 3
          },
          {
            "render": function(data, type, row, meta) {
              var html ='暂无图片';
              if(data!=null && data!=''){
                html = '<img src="'+data+'" style="height: 40px;"/>';
              }
              return html;
            },
            "targets": 4
          },
          {
            "render": function(data, type, row, meta) {
              var html = '<div class="action-buttons">';
              html += '<a href="javascript:void(0)" onclick="userIdCard(' + row.id + ',\'ys\')" class="blue" title="银盛"><i style="font: normal normal normal 14px/1 FontAwesome;">银盛</i></a>';
              html += '<a href="javascript:void(0)" onclick="userIdCard(' + row.id + ',\'mb\')" class="blue" title="摩宝"><i style="font: normal normal normal 14px/1 FontAwesome;">摩宝</i></a>';
              html += '</div>';
              return html;
            },
            "targets": 6
          },
          {
            "render": function(data, type, row, meta) {
              var html ='否';
              if(data==1){
                html = '是';
              }
              return html;
            },
            "targets": 8
          },
          {
            "render": function(data, type, row, meta) {
              var html ='正常';
              if(row.account_status==1){
                html = '注销';
              }
              if(row.account_status==2){
                html = '禁用';
              }
              var html1 ='开起';
              if(data==0){
                html1 = '未开起';
              }
              return html+"/"+html1;
            },
            "targets": 9
          },

          {
            "render": function(data, type, row, meta) {
              if(data!=null && data!=''){
                return data.substring(0,19)
              }
              return "无";
            },
            "targets": 10
          },
          {
            "render": function(data, type, row, meta) {
              if(data>0){
                if(row.blackType==1){
                  return '<dev style="color: red;">冻结</i></dev>';
                }
                return "冻结";
              }
              return "正常";
            },
            "targets": 11
          },
          {
            "render": function(data, type, row, meta) {
              var str = data;
              var html = "";
              if(str==null || str =='') {
                return "";
              }else{
                html = '<a href="javascript:void(0)" onclick="aliUnBind(' + row.id + ')" class="blue" title="解除绑定"><i class="ace-icon fa fa-pencil bigger-130">解除绑定</i></a>';
                if (row.alipayStatus == 1) {
                  return html + "</br>" + data + "(已拉黑)";
                }
                return html + "</br>" + data;
              }
            },
            "targets": 12
          },
          {
            "render": function(data, type, row, meta) {
              return '<a href="javascript:void(0)" onclick="ipadds(\'' + data + '\')" class="blue" title="解除绑定">'+data+'</a>';
            },
            "targets": 14
          },

          {
            "render": function(data, type, row, meta) {
              var html = '<div class="action-buttons">';
              if(row.account_status==0){
                html += '<a href="javascript:void(0)" onclick="accountStatus(' + row.id + ',2)" class="blue" title="禁用"><i class="ace-icon fa fa-pencil bigger-130">禁用</i></a>';
              }
              if(row.account_status==2){
                html += '<a href="javascript:void(0)" onclick="accountStatus(' + row.id + ',0)" class="blue" title="解禁"><i class="ace-icon fa fa-pencil bigger-130">解禁</i></a>';
              }
              html += '<a href="javascript:void(0)" onclick="syncMoney(' + row.id + ')" class="blue" title="同步余额"><i class="ace-icon fa fa-pencil bigger-130">同步余额</i></a>';
              if(row.userWithdrawBlack>0){
                html += '<a href="javascript:void(0)" onclick="userWithdrawBlack(' + row.id + ',1,\'解除提现\')" class="blue" title="解除提现"><i class="ace-icon fa fa-pencil bigger-130">解除提现</i></a>';
              }else{
                html += '<a href="javascript:void(0)" onclick="userWithdrawBlack(' + row.id + ',2,\'冻结提现\')" class="blue" title="冻结提现"><i class="ace-icon fa fa-pencil bigger-130">冻结提现</i></a>';
              }
              html += '<a href="/app/user/account/flow/index?uid='+row.id+'"  class="blue" title="交易明细"><i class="ace-icon fa fa-pencil bigger-130">交易明细</i></a>';
              html += '<a href="/app/user/red/index?uid='+row.id+'"  class="blue" title="红包明细"><i class="ace-icon fa fa-pencil bigger-130">红包明细</i></a>';
              html += '<a href="/app/user/transfer/index?uid='+row.id+'"  class="blue" title="转账明细"><i class="ace-icon fa fa-pencil bigger-130">转账明细</i></a>';
              if(row.alipayStatus==2){
                html += '<a href="javascript:void(0)" onclick="aliBlack(' + row.id + ',\'' + row.alipayUid + '\')" class="blue" title="拉黑aliId"><i class="ace-icon fa fa-pencil bigger-130">拉黑aliId</i></a>';
              }else{
                html += '<a href="javascript:void(0)" onclick="aliBlackUn(' + row.id + ',\'' + row.alipayUid + '\')" class="blue" title="取消aliId"><i class="ace-icon fa fa-pencil bigger-130">取消aliId</i></a>';
              }
              html += '<a href="javascript:void(0);" onclick="redisInfo(' + row.phone + ')" class="blue" title="清除缓存"><i class="ace-icon fa fa-pencil bigger-130">清除缓存</i></a>';
              html += '<a href="/app/user/friend/index?uid='+row.id+'"  class="blue" title="好友信息"><i class="ace-icon fa fa-pencil bigger-130">好友信息</i></a>';
              html += '</div>';
              return html;
            },
            "targets": 16
          }
        ]
      });
    });

  });

  $("#phoneRedis").click(function(){
    var phone = $("#phone").val();
    redisInfo(phone);
  });
  function syncMoney(id){
    var str = "是否同步账户金额";
    // 询问框
    layer.confirm(str, {
      btn: ['确定','取消']
    }, function(){
      $.ajax({
        type:"post",
        url:"${path}/app/user/sync/money",
        dataType:"json",
        data:{id:id},
        success:function(data){
          if(data.code == 0){
            layer.open({
              type: 1,
              shade: 0.8,
              offset: 'auto',
              shadeClose: true,//点击外围关闭弹窗
              scrollbar: false,//不现实滚动条
              title: "同步信息", //不显示标题
              area: ['40%', '45%'],
              content: "<div style='display:flex;justify-content:center;'>" +
                      "<textarea id='refundAddress' style='width:80%;height:60px;margin-top: 8px'> " +
                      " 提示："+data.msg+" \n " +
                      " 原有余额："+data.balance+"\n " +
                      " 同步金额："+data.cashAmount+"</textarea>" +
                      "</div>",
              btn:['确认'],
              btnAlign:'c',
              yes: function (index,layero) {
                if(tables){
                  tables.dataTable().fnDraw();
                }
              }
              // layer.alert(data.msg,{icon:1}, function(){
              //   location.reload();
              // });
            });
          }else{
            layer.alert(data.msg, {icon: 2});
          }
        }
      });
    });
  }
  function userIdCard(uid,type){
    layer.open({
      type: 1,
      shade: 0.8,
      offset: 'auto',
      shadeClose: true,//点击外围关闭弹窗
      scrollbar: false,//不现实滚动条
      title: "实名信息", //不显示标题
      area: ['20%', '25%'],
      content: "<div class='layui-layer-content' style='top: 20px;'>" +
              "<div style='display:flex;justify-content:center;'>" +
              "<div class=\"form-group\"><label class=\"font-normal\">银行卡：</label>111111</div>" +
              "</div>" +
              "<div style='display:flex;justify-content:center;'>" +
              "<div class=\"form-group\"><label class=\"font-normal\">姓名：</label>111111</div>" +
              "</div></div>",
      btn:['确认'],
      btnAlign:'c',
      yes: function (index,layero) {
        layer.close(index);
      }
      // layer.alert(data.msg,{icon:1}, function(){
      //   location.reload();
      // });
    });
  }
  function accountStatus(uid,status){
    layer.confirm("是否禁用当前人员", function (e) {
      var index = layer.load(2);
      $.ajax({
        type:"post",
        url:"${path}/app/user/update/status",
        dataType:"json",
        data:{uid:uid,status:status},
        success:function(data){
          layer.close(index);
          if(data.code ==0){
            var index2 = layer.alert(data.msg,{icon:1}, function(){
              if(tables){
                tables.dataTable().fnDraw();
                layer.close(index2);
              }
            });
          }else{
            layer.alert(data.msg,{icon:2});
          }
        },
        error:function (data) {
          layer.close(index);
        }
      });
    });
  }
  function userWithdrawBlack(uid,status,str){
    layer.confirm("当前人员是否"+str, function (e) {
      var index = layer.load(2);
      $.ajax({
        type:"post",
        url:"${path}/app/user/withdraw/black/status",
        dataType:"json",
        data:{uid:uid,status:status},
        success:function(data){
          layer.close(index);
          if(data.code ==0){
            var index2 = layer.alert(data.msg,{icon:1}, function(){
              if(tables){
                tables.dataTable().fnDraw();
                layer.close(index2);
              }
            });
          }else{
            layer.alert(data.msg,{icon:2});
          }
        },
        error:function (data) {
          layer.close(index);
        }
      });
    });
  }
  function aliBlack(uid,alipayUid){
    layer.confirm("当前人员是否拉黑aliId", function (e) {
      var index = layer.load(2);
      $.ajax({
        type:"post",
        url:"${path}/app/user/ali/black",
        dataType:"json",
        data:{userId:uid,alipayUid:alipayUid},
        success:function(data){
          layer.close(index);
          if(data.code ==0){
            var index2 = layer.alert(data.msg,{icon:1}, function(){
              if(tables){
                tables.dataTable().fnDraw();
                layer.close(index2);
              }
            });
          }else{
            layer.alert(data.msg,{icon:2});
          }
        },
        error:function (data) {
          layer.close(index);
        }
      });
    });
  }
  function aliBlackUn(uid,alipayUid){
    layer.confirm("当前人员是否解除拉黑aliId", function (e) {
      var index = layer.load(2);
      $.ajax({
        type:"post",
        url:"${path}/app/user/ali/black/un",
        dataType:"json",
        data:{userId:uid,alipayUid:alipayUid},
        success:function(data){
          layer.close(index);
          if(data.code ==0){
            var index2 = layer.alert(data.msg,{icon:1}, function(){
              if(tables){
                tables.dataTable().fnDraw();
                layer.close(index2);
              }
            });
          }else{
            layer.alert(data.msg,{icon:2});
          }
        },
        error:function (data) {
          layer.close(index);
        }
      });
    });
  }

  function redisInfo(phone){
    if(phone==""){
      layer.alert("请输入电话号码",{icon:2});
    }
    layer.confirm("当前人员是否清除缓存", function (e) {
      var index = layer.load(2);
      $.ajax({
        type:"post",
        url:"${path}/app/user/redisInfo",
        dataType:"json",
        data:{phone:phone},
        success:function(data){
          layer.close(index);
          if(data.code ==0){
            var index2 = layer.alert(data.msg,{icon:1}, function(){
              if(tables){
                tables.dataTable().fnDraw();
                layer.close(index2);
              }
            });
          }else{
            layer.alert(data.msg,{icon:2});
          }
        },
        error:function (data) {
          layer.close(index);
        }
      });
    });
  }
  function userConfig(userId){
    $.ajax({
      type:"post",
      url:"${path}/app/user/user/config",
      dataType:"json",
      data:{userId:userId},
      success:function(data){
        if(data.code == 0){
          var html = '<div style="padding: 20px">';
          html += '<table class="layui-table1">';
          html += '<tbody>';
          html += '<tr>';
          html += '<th>手机号屏蔽:';
          if(data.data.hide_phone==1){
            html += '开';
          }else{
            html += "关";
          }
          html += '</th>';
          html += '<th>群聊屏蔽:';
          if(data.data.hide_group==1){
            html += '开';
          }else{
            html += "关";
          }
          html += '</th>' ;
          html += '<th>二维码屏蔽:';
          if(data.data.hide_qrcode==1){
            html += '开';
          }else{
            html += "关";
          }
          html += '</th>' ;
          html += '</tr>';
          html += '<tr>';
          html += '<th>添加好友需要验证:';
          if(data.data.friend_verify==1){
            html += '开';
          }else{
            html += "关";
          }
          html += '</th>' ;
          html += '<th>邀请进群需要验证:';
          if(data.data.group_verify==1){
            html += '开';
          }else{
            html += "关";
          }
          html += '</th>' ;
          html += '<th>是否开启声音:';
          if(data.data.notice_sounds_tip==1){
            html += '开';
          }else{
            html += "关";
          }
          html += '</th>' ;
          html += '</tr>';
          html += '<tr>';
          html += '<th>用户禁止通过二维码添加好友:';
          if(data.data.hide_alias==1){
            html += '开';
          }else{
            html += "关";
          }
          html += '</th>' ;
          html += '</tr>';
          html += '<tr>';
          html += '<th>是否开启复制好友:';
          if(data.data.friendsCopy==1){
            html += '开';
          }else{
            html += "关";
          }
          html += '</th>' ;
          html += '<th>' ;
          if(data.data.friendsCopy==1){
            html += '<a href="javascript:void(0)" onclick="friendsCopy('+userId+',0)">关闭</a>';
          }else{
            html += '<a href="javascript:void(0)"onclick="friendsCopy('+userId+',1)">开启</a>';
          }
          html += '</th>' ;
          html += '</tr>';
          html += '</tbody>';
          html += '</table>';
          html += '</div>';
          layer.open({
            type: 1,
            shade: 0.8,
            offset: 'auto',
            shadeClose: true//点击外围关闭弹窗
            ,content:html
            ,btn: '关闭'
            ,btnAlign: 'c' //按钮居中
            ,title: "用户配置信息" //不显示标题
            ,area: ['40%', '45%']
            ,yes: function(){
              layer.closeAll();
            }
          });
        }else{
          layer.alert(data.msg, {icon: 2});
        }
      }
    });
  }
  function aliUnBind(uid){
    if(uid==0){
      layer.alert("请输选择人员",{icon:2});
    }
    layer.confirm("是否清除当前人员绑定的支付宝信息", function (e) {
      var index = layer.load(2);
      $.ajax({
        type:"post",
        url:"${path}/app/user/ali/un/bind",
        dataType:"json",
        data:{uid:uid},
        success:function(data){
          layer.close(index);
          if(data.code ==0){
            var index2 = layer.alert(data.msg,{icon:1}, function(){
              if(tables){
                tables.dataTable().fnDraw();
                layer.close(index2);
              }
            });
          }else{
            layer.alert(data.msg,{icon:2});
          }
        },
        error:function (data) {
          layer.close(index);
        }
      });
    });
  }

  function ipadds(ip){

    var index = layer.load(2);
    $.ajax({
      type:"get",
      url:"/app/user/ip/adds",
      dataType:"json",
      data:{ip:ip},
      success:function(data){
        layer.close(index);
        if(data.code ==0){
          layer.alert(data.adds.addr,{icon:1});
        }
      },
      error:function (data) {
        layer.close(index);
      }
    });


  }

  function friendsCopy(userid,type){
    var index = layer.load(2);
    $.ajax({
      type:"get",
      url:"/app/user/friends/copy",
      dataType:"json",
      data:{userId:userid,type:type},
      success:function(data){
        layer.close(index);
        if(data.code ==0){
          layer.close(index);
          userConfig(userid);
        }
      },
      error:function (data) {
        layer.close(index);
      }
    });

  }
</script>
</body>
</html>
